package com.telit.firecommand.service.impl;

import com.telit.common.util.JwtTokenUtils;
import com.telit.firecommand.dao.WebsocketPushMsgLogDao;
import com.telit.firecommand.entity.WebsocketPushMsgLog;
import com.telit.firecommand.service.WebSocketPushMsgLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author zhouyu
 * @description websocket消息推送日志
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class WebSocketPushMsgLogServiceImpl implements WebSocketPushMsgLogService {

    @Autowired
    private WebsocketPushMsgLogDao websocketPushMsgLogDao;


    @Override
    public void addPushMsgLog(WebsocketPushMsgLog websocketPushMsgLog) {
        websocketPushMsgLogDao.insertSelective(websocketPushMsgLog);
    }

    @Override
    public void changeToHasRead(Integer eventType, Long eventId) {
        Long userId = JwtTokenUtils.getId();
        WebsocketPushMsgLog websocketPushMsgLog = new WebsocketPushMsgLog();
        websocketPushMsgLog.setUserId(userId);
        websocketPushMsgLog.setEventId(eventId);
        websocketPushMsgLog.setEventType(eventType);
        websocketPushMsgLogDao.insertSelective(websocketPushMsgLog);
    }

    @Override
    public List<Long> queryHasReadMsg(Integer eventType, Long userId) {
        return websocketPushMsgLogDao.queryHasReadMsg(eventType,userId);
    }

    @Override
    public Long queryHasRead(Integer eventType, Long fireId) {
        return websocketPushMsgLogDao.queryHasRead(eventType,fireId);
    }
}
